<?php

namespace App\Models;

use App\Models\Base;

/**
 * Class Consultation
 *
 * @property int $id
 * @property int|null $user_id 用户iD
 * @property string $describe 描述
 * @property string|null $images 图片uri，逗号分隔
 * @property string|null $created_at 创建时间
 * @method static \Illuminate\Database\Eloquent\Builder|Consultation newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Consultation newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Consultation query()
 * @method static \Illuminate\Database\Eloquent\Builder|Consultation whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Consultation whereDescribe($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Consultation whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Consultation whereImages($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Consultation whereUserId($value)
 * @mixin \Eloquent
 * @property int|null $status 状态（1：平台待回复，2：病员待回复）
 * @method static \Illuminate\Database\Eloquent\Builder|Consultation whereStatus($value)
 */
class Consultation extends Base
{


       protected $table = 'consultations';
       protected $fillable = [
           'user_id','describe', 'images', 'created_at','status'
       ];

       public $timestamps = false;


    /**
     * 获取列表
     * @param array $params 条件参数
     * @param array $fields 查询的字段
     * @return mixed
     */
    protected function getList($params = [], $fields = ['*']){
        $lists = $this->select($fields)
            ->where(function ($query) use ($params) {
                if(isset($params['describe']) && $params['describe']) {
                    $query ->where('describe','like','%' . $params['describe'] . '%');
                }
            })
            ->orderBy('id', 'desc')
            ->paginate(config('app.limit'));
        foreach ($lists->items() as $item) {
            $item->nickname = User::whereId($item->user_id)->value('nickname');
        }
        return $lists;
    }
}
